
dnl ###########################################################################
dnl #									      #
dnl # 	       Autoconf input file for GNU Interactive Tools 4.3.11	      #
dnl #   Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.   #
dnl #									      #
dnl ###########################################################################


dnl #################################
dnl # Initializing autoconf stuff.  #
dnl #################################

AC_REVISION($Revision: 4.3.11 $)
AC_INIT(src/git.c)
AC_CONFIG_HEADER(config.h)
AC_PREREQ(2.9)


dnl ################################################
dnl # Set up the product name and version number.  #
dnl ################################################

PRODUCT="GNU Interactive Tools"
VERSION="4.3.11"


dnl ###################
dnl # The message...  #
dnl ###################

echo
echo
echo "                ############################################"
echo "                # Configuring GNU Interactive Tools 4.3.11 #"
echo "                ############################################"
echo
echo
echo "     ******************************************************************"
echo "     *     WARNING: some old losing shells fail to run './configure', *"
echo "     * trying to execute configure itself.  You can prevent  this  by *"
echo "     * running 'sh configure'.  The configure script will be executed *"
echo "     * by /bin/sh.                                                    *"
echo "     ******************************************************************"
echo
echo
echo "     ******************************************************************"
echo "     *     If you find bugs in this software or in  the  installation *"
echo "     * procedure please send a description to tudorh@pub.ro.          *"
echo "     ******************************************************************"
echo
echo

echo "5 seconds delay..."
sleep 5
echo


dnl ################################################
dnl # Check for a BSD compatible install program.  #
dnl ################################################

AC_PROG_INSTALL

dnl #########################################
dnl # Check for the canonical system name.  #
dnl #########################################

AC_CANONICAL_HOST

HOST=$host


dnl ###################################################################
dnl # Checking the system type. We are especially looking for Linux.  #
dnl ###################################################################

if test "$host_os" = "linux"; then
    AC_DEFINE(HAVE_LINUX)
else
    if test `echo "$host_os" | cut -c1-4` = "hpux"; then
	AC_DEFINE(HAVE_HPUX)
    fi
fi


dnl #############################
dnl # Checking the C compiler.  #
dnl #############################

AC_PROG_CC


dnl ######################################
dnl # Check the command line arguments.  #
dnl ######################################

AC_ARG_WITH(terminfo,
	[  --with-terminfo         use terminfo insted of termcap],
	TERMINFO="$withval",
	TERMINFO="no")

AC_ARG_ENABLE(gcc-warnings,
	[  --enable-gcc-warnings   more gcc warnings for debugging purposes],
	GCC_WARNINGS="$enableval",
	GCC_WARNINGS="no")

dnl #####################################################################
dnl # Increase the warnings level if using GNU C.			#
dnl #####################################################################

if test "$CC" = "gcc"; then
    AC_DEFINE(HAVE_GCC)
    CFLAGS="$CFLAGS -Wall";
    if test "$GCC_WARNINGS" = "yes"; then
	CFLAGS="$CFLAGS -Waggregate-return -Wbad-function-cast -Wcast-align\
			-Wtraditional -Winline -Wpointer-arith -Wcast-qual";
    fi
fi


dnl ########################################################################
dnl # Checking for some UNIX variants.  These ones need special treatement #
dnl # due to exceptional oddities in their header files or libraries.	   #
dnl ########################################################################

AC_AIX
AC_ISC_POSIX
AC_MINIX
AC_CHECK_LIB(sun, getpwnam)


dnl #################################
dnl # Checking the C preprocessor.  #
dnl #################################

AC_PROG_CPP


dnl ##########################################
dnl # Checking for standard C header files.  #
dnl ##########################################

AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h stdlib.h string.h memory.h values.h)


dnl ################################################
dnl # Checking for system dependent header files.  #
dnl ################################################

AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/vfs.h sys/filsys.h fcntl.h)
AC_CHECK_HEADERS(sys/statfs.h sys/dustat.h sys/statvfs.h)


dnl ###################################################################
dnl # Checking for system specific directory functions declarations.  #
dnl ###################################################################

AC_HEADER_DIRENT


dnl ####################################################################
dnl # Checking whether the C compiler do support the 'const' keyword.  #
dnl ####################################################################

AC_C_CONST


dnl ###############################################################
dnl # Checking for predefined C types.  Fixing when necessary...  #
dnl ###############################################################

AC_TYPE_SIGNAL
AC_TYPE_PID_T
AC_TYPE_UID_T
AC_TYPE_MODE_T
AC_TYPE_SIZE_T


dnl ###################################################
dnl # Checking how to include time.h and sys/time.h.  #
dnl ###################################################

AC_CHECK_HEADERS(sys/time.h)
AC_HEADER_TIME


dnl #########################################################################
dnl # Checking whether the system supports long file names.  GIT will issue #
dnl # a warning at run time if long file names are not supported.	    #
dnl #########################################################################

AC_SYS_LONG_FILE_NAMES


dnl ####################################
dnl # Checking the sys/stat.h macros.  #
dnl ####################################

AC_HEADER_STAT


dnl ##################################################################
dnl # Checking whether the system supports the lstat() system call.  #
dnl ##################################################################

AC_CHECK_FUNCS(lstat)


dnl ########################################################################
dnl # Checking for the presence of the strerror().  This function is a new #
dnl # feature of ANSI C and many older C systems do not support it yet.    #
dnl ########################################################################

AC_CHECK_FUNCS(strerror)


dnl ####################################################################
dnl # Checking for the presence of the strcasecmp().  This function is #
dnl # derived from BSD 4.3 and other systems might not have it.	       #
dnl ####################################################################

AC_CHECK_FUNCS(strcasecmp)


dnl ####################################################################
dnl # Checking for the presence of the strcasecmp().  This function is #
dnl # a GNU extension so only a few systems support it.	 Too bad :-(   #
dnl ####################################################################

AC_CHECK_FUNCS(strncasecmp)


dnl #################################################################
dnl # Checking for the presence of the strstr().  Older BSD systems #
dnl # might not have it.                                            #
dnl #################################################################

AC_CHECK_FUNCS(strstr)


dnl ##################################################################
dnl # Checking for the presence of the memmove().  Older BSD systems #
dnl # might not have it.                                             #
dnl ##################################################################

AC_CHECK_FUNCS(memmove)


dnl #################################################################
dnl # Checking for the presence of the putenv().  Older BSD systems #
dnl # might not have it.                                            #
dnl #################################################################

AC_CHECK_FUNCS(putenv)


dnl #################################################################
dnl # Checking for the presence of the setenv().  Older BSD systems #
dnl # might use it instead of putenv.                               #
dnl #################################################################

AC_CHECK_FUNCS(setenv)


dnl #################################################################
dnl # Checking for the presence of the getcwd().  Older BSD systems #
dnl # might not have it.                                            #
dnl #################################################################

AC_CHECK_FUNCS(getcwd)


dnl ########################################################################
dnl # This configure.in code has been stolen from GNU fileutils-3.12.  Its #
dnl # job is to detect a method to get file system information.	           #
dnl ########################################################################

AC_CHECKING(how to get filesystem space usage)
space=no

# Here we'll compromise a little (and perform only the link test)
# since it seems there are no variants of the statvfs function.
if test $space = no; then
  # SVR4
  AC_CHECK_FUNCS(statvfs)
  if test $ac_cv_func_statvfs = yes; then
    space=yes
    AC_DEFINE(STAT_STATVFS)
  fi
fi

if test $space = no; then
  # DEC Alpha running OSF/1
  AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
  AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
  [AC_TRY_RUN([
#include <sys/param.h>
#include <sys/types.h>
#include <sys/mount.h>
  main ()
  {
    struct statfs fsd;
    fsd.f_fsize = 0;
    exit (statfs (".", &fsd, sizeof (struct statfs)));
  }],
  fu_cv_sys_stat_statfs3_osf1=yes,
  fu_cv_sys_stat_statfs3_osf1=no,
  fu_cv_sys_stat_statfs3_osf1=no)])
  AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
  if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
    space=yes
    AC_DEFINE(STAT_STATFS3_OSF1)
  fi
fi

if test $space = no; then
# AIX
  AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
member (AIX, 4.3BSD)])
  AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
  [AC_TRY_RUN([
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif
  main ()
  {
  struct statfs fsd;
  fsd.f_bsize = 0;
  exit (statfs (".", &fsd));
  }],
  fu_cv_sys_stat_statfs2_bsize=yes,
  fu_cv_sys_stat_statfs2_bsize=no,
  fu_cv_sys_stat_statfs2_bsize=no)])
  AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
  if test $fu_cv_sys_stat_statfs2_bsize = yes; then
    space=yes
    AC_DEFINE(STAT_STATFS2_BSIZE)
  fi
fi

if test $space = no; then
# SVR3
  AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
  AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
  [AC_TRY_RUN([#include <sys/types.h>
#include <sys/statfs.h>
  main ()
  {
  struct statfs fsd;
  exit (statfs (".", &fsd, sizeof fsd, 0));
  }],
    fu_cv_sys_stat_statfs4=yes,
    fu_cv_sys_stat_statfs4=no,
    fu_cv_sys_stat_statfs4=no)])
  AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
  if test $fu_cv_sys_stat_statfs4 = yes; then
    space=yes
    AC_DEFINE(STAT_STATFS4)
  fi
fi

if test $space = no; then
# 4.4BSD and NetBSD
  AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
member (4.4BSD and NetBSD)])
  AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
  [AC_TRY_RUN([#include <sys/types.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
  main ()
  {
  struct statfs fsd;
  fsd.f_fsize = 0;
  exit (statfs (".", &fsd));
  }],
  fu_cv_sys_stat_statfs2_fsize=yes,
  fu_cv_sys_stat_statfs2_fsize=no,
  fu_cv_sys_stat_statfs2_fsize=no)])
  AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
  if test $fu_cv_sys_stat_statfs2_fsize = yes; then
    space=yes
    AC_DEFINE(STAT_STATFS2_FSIZE)
  fi
fi

if test $space = no; then
  # Ultrix
  AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
  AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
  [AC_TRY_RUN([#include <sys/types.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_FS_TYPES_H
#include <sys/fs_types.h>
#endif
  main ()
  {
  struct fs_data fsd;
  /* Ultrix's statfs returns 1 for success,
     0 for not mounted, -1 for failure.  */
  exit (statfs (".", &fsd) != 1);
  }],
  fu_cv_sys_stat_fs_data=yes,
  fu_cv_sys_stat_fs_data=no,
  fu_cv_sys_stat_fs_data=no)])
  AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
  if test $fu_cv_sys_stat_fs_data = yes; then
    space=yes
    AC_DEFINE(STAT_STATFS2_FS_DATA)
  fi
fi

dnl Not supported
dnl if test $space = no; then
dnl # SVR2
dnl AC_TRY_CPP([#include <sys/filsys.h>],
dnl   AC_DEFINE(STAT_READ_FILSYS) space=yes)
dnl fi


dnl ###########################################################################
dnl # If the GNU readline library is installed on the system, we will use its #
dnl # tilde_expand() and history functions.  Otherwise, we have  to  use  the #
dnl # versions of tilde.c and history.c included in the package.  These files #
dnl # belong to the GNU readline library version 2.0.1.			      #
dnl ###########################################################################

AC_CHECK_LIB(readline, tilde_expand)
AC_FUNC_CHECK(tilde_expand,,
	      GIT_OBJS="$GIT_OBJS tilde.o"
	      GITPS_OBJS="$GITPS_OBJS tilde.o"
	      GITVIEW_OBJS="$GITVIEW_OBJS tilde.o")
AC_FUNC_CHECK(using_history,,
	      GIT_OBJS="$GIT_OBJS history.o")


dnl ####################################################
dnl # Checking if ioctl(1, TIOCGWINSZ, &winsz) works.  #
dnl ####################################################

AC_MSG_CHECKING([for struct winsz])

AC_CACHE_VAL(git_cv_struct_winsz,
    git_cv_struct_winsz="no"
    AC_TRY_LINK(
	[#include <sys/types.h>
	 #include <sys/ioctl.h>
	 #if defined TIOCGSIZE && !defined TIOCGWINSZ
	 #define TIOCGWINSZ TIOCGSIZE
	 #endif],
	[{
	    struct winsize winsz;
	    ioctl(1, TIOCGWINSZ, &winsz);
	    winsz.ws_col = winsz.ws_row;
	}],
	git_cv_struct_winsz="yes"
    )
)

if test "$git_cv_struct_winsz" = "yes"; then
    AC_DEFINE(HAVE_WINSZ)
fi

AC_MSG_RESULT([$git_cv_struct_winsz])


dnl ######################################################################
dnl # Checking for compilers that do not support constructs combinations #
dnl # of ANSI C like prototypes & K&R definitions.  For B.O.S. systems.	 #
dnl ######################################################################

AC_MSG_CHECKING([for dumb C compiler])

AC_CACHE_VAL(git_cv_dumb_cc,
    git_cv_dumb_cc="yes"
    AC_TRY_LINK(
	[void tst(char);
	 void tst(i)
	     char i;
	 {}],
	[{
	    tst('A');
	}],
	git_cv_dumb_cc="no"
    )
)

if test "$git_cv_dumb_cc" = "yes"; then
    AC_DEFINE(HAVE_DUMB_CC)
fi

AC_MSG_RESULT([$git_cv_dumb_cc])


dnl #############################################
dnl # Checking if struct utsname is available.  #
dnl #############################################

AC_MSG_CHECKING([for struct utsname])

AC_CACHE_VAL(git_cv_struct_utsname,
    git_cv_struct_utsname="no"
    AC_TRY_LINK(
	[#include <sys/utsname.h>],
	[{
	    char *ptr;
	    struct utsname u;

	    uname(&u);
	    ptr = u.nodename;
	    ptr = u.sysname;
	    ptr = u.machine;
	}],
	git_cv_struct_utsname="yes"
    )
)

if test "$git_cv_struct_utsname" = "yes"; then
    AC_DEFINE(HAVE_UTSNAME)
fi

AC_MSG_RESULT([$git_cv_struct_utsname])


dnl ######################################################
dnl # Checking for POSIX compatible terminal interface.  #
dnl ######################################################

AC_MSG_CHECKING([for POSIX compatible terminal interface])

AC_CACHE_VAL(git_cv_sys_posix_tty,
    git_cv_sys_posix_tty="no"
    AC_TRY_LINK(
	[#include <termios.h>],
	[{
	    struct termios term;

	    tcgetattr(0, &term);
	}],
	git_cv_sys_posix_tty="yes"
    )
)

if test "$git_cv_sys_posix_tty" = "yes"; then
    AC_DEFINE(HAVE_POSIX_TTY)
fi

AC_MSG_RESULT([$git_cv_sys_posix_tty])


dnl #########################################################
dnl # Checking for System V compatible terminal interface.  #
dnl #########################################################

AC_MSG_CHECKING([for System V compatible terminal interface])

AC_CACHE_VAL(git_cv_sys_systemv_tty,
    git_cv_sys_systemv_tty="no"
    AC_TRY_LINK(
	[#include <termio.h>],
	[{
	    struct termio term;

	    ioctl(0, TCGETA, &term);
	}],
	git_cv_sys_systemv_tty="yes"
    )
)

if test "$git_cv_sys_systemv_tty" = "yes"; then
    AC_DEFINE(HAVE_SYSTEMV_TTY)
fi

AC_MSG_RESULT([$git_cv_sys_systemv_tty])


dnl ####################################################
dnl # Checking for BSD compatible terminal interface.  #
dnl ####################################################

AC_MSG_CHECKING([for BSD compatible terminal interface])

AC_CACHE_VAL(git_cv_sys_bsd_tty,
    git_cv_sys_bsd_tty="no"
    AC_TRY_LINK(
	[#include <sgtty.h>],
	[{
	    struct sgttyb arg;
	    struct tchars targ;
	    struct ltchars ltarg;

	    ioctl(0, TIOCGETP,&arg);
	    ioctl(0, TIOCGETC,&targ);
	    ioctl(0, TIOCGLTC,&ltarg);
	}],
	git_cv_sys_bsd_tty="yes"
    )
)

if test "$git_cv_sys_bsd_tty" = "yes"; then
    AC_DEFINE(HAVE_BSD_TTY)
fi

AC_MSG_RESULT([$git_cv_sys_bsd_tty])


dnl #######################################################
dnl # Checking the terminal capabilities library to use.  #
dnl #######################################################

define(git_TERMINFO_LIBRARY,
[    AC_CHECK_LIB(ncurses, tgetent, AC_DEFINE(HAVE_LIBTERMINFO)
				 LIBS="$LIBS -lncurses"
				 TERMLIB_FOUND="yes",
	AC_CHECK_LIB(termlib, tgetent, AC_DEFINE(HAVE_LIBTERMINFO)
				    LIBS="$LIBS -ltermlib"
				    TERMLIB_FOUND="yes",
	    AC_CHECK_LIB(curses, tgetent, AC_DEFINE(HAVE_LIBTERMINFO)
				       LIBS="$LIBS -lcurses"
				       TERMLIB_FOUND="yes",
		AC_CHECK_LIB(tinfo, tgetent, AC_DEFINE(HAVE_LIBTERMINFO)
					  LIBS="$LIBS -ltinfo"
					  TERMLIB_FOUND="yes",
		    AC_CHECK_LIB(terminfo, tgetent, AC_DEFINE(HAVE_LIBTERMINFO)
						 LIBS="$LIBS -lterminfo"
						 TERMLIB_FOUND="yes",
			TERMLIB_FOUND="no"
		    )
		)
	    )
	)
    )
]
)dnl

if test "$TERMINFO" = "yes"; then
    git_TERMINFO_LIBRARY
    if test "$TERMLIB_FOUND" = "no"; then
	AC_CHECK_LIB(termcap, tgetent,
		     AC_DEFINE(HAVE_LIBTERMCAP)
		     LIBS="$LIBS -ltermcap"
		     TERMLIB_FOUND="yes")
    fi
else
    AC_CHECK_LIB(termcap, tgetent,
		 AC_DEFINE(HAVE_LIBTERMCAP)
		 LIBS="$LIBS -ltermcap"
		 TERMLIB_FOUND="yes",
		 git_TERMINFO_LIBRARY)
fi

if test "$TERMLIB_FOUND" = "no"; then
    AC_MSG_ERROR([no library for handling terminal capabilities])
fi


dnl #######################################################################
dnl # Checking the makeinfo utility.  If we can't find it, we can't build #
dnl # build the info documentation.				          #
dnl #######################################################################

AC_PROGRAM_CHECK(MAKEINFO, makeinfo, makeinfo, false)
if test "$MAKEINFO" = "false"; then
    AC_MSG_WARN(***** makeinfo utility not found *****)
fi


dnl #######################################################################
dnl # Checking the texi2dvi utility.  If we can't find it, we can't build #
dnl # build the dvi documentation.				          #
dnl #######################################################################

AC_PROGRAM_CHECK(TEXI2DVI, texi2dvi, texi2dvi, false)
if test "$TEXI2DVI" = "false"; then
    AC_MSG_WARN(***** texi2dvi utility not found *****)
fi


dnl ##########################################################################
dnl # According to Joachim Baumann, for Solaris 2.3 & Solaris 2.4 (at least) #
dnl # -lucb should be included after -ltermcap.  This has not been tested !! #
dnl ##########################################################################

if test "$TERMINFO" = "no"; then
    if test "$host_os" = "solaris2.3" -o "$host_os" = "solaris2.4"; then
	AC_CHECK_LIB(ucb, tgetent, , , $LIBS)
    fi
fi

dnl #######################################
dnl # Make final variable substitutions.  #
dnl #######################################

AC_SUBST(PRODUCT)dnl
AC_SUBST(VERSION)dnl
AC_SUBST(HOST)dnl
AC_SUBST(INSTALL)dnl
AC_SUBST(INSTALL_PROGRAM)dnl
AC_SUBST(INSTALL_DATA)dnl
AC_SUBST(CFLAGS)dnl
AC_SUBST(GIT_OBJS)dnl
AC_SUBST(GITPS_OBJS)dnl
AC_SUBST(GITVIEW_OBJS)dnl


dnl ##########
dnl # Done.  #
dnl ##########

AC_OUTPUT(Makefile src/Makefile info/Makefile man/Makefile term/Makefile
	  version.h)
